home *** CD-ROM | disk | FTP | other *** search
Wrap
/* * SFskyedit - Star Fighter 3000 sky colours editor * DCS dialogue * Copyright (C) 2001 Chris Bazley * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public Licence as published by * the Free Software Foundation; either version 2 of the Licence, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public Licence for more details. * * You should have received a copy of the GNU General Public Licence * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* ANSI library files */ #include <string.h> #include <stdbool.h> /* RISC OS library files */ #include "toolbox.h" #include "event.h" #include "dcs.h" /* My library files */ #include "Macros.h" #include "err.h" #include "FilePerc.h" #include "InputFocus.h" /* Local headers */ #include "EditSky.h" #include "DCS_dialogue.h" #include "SFSSaveBox.h" #include "Utils.h" ObjectId dcs_sharedid = NULL_ObjectId; bool dcs_openparent = false; /* ----------------------------------------------------------------------- */ /* Function prototypes */ static ToolboxEventHandler _DCS_actions_handler; /* ----------------------------------------------------------------------- */ /* Public functions */ void DCS_initialise(ObjectId dcs_id) { /* Record ID */ dcs_sharedid = dcs_id; /* Install handlers */ EF(event_register_toolbox_handler(dcs_id, -1, _DCS_actions_handler, NULL)); EF(event_register_toolbox_handler(dcs_id, DCS_AboutToBeShown, InputFocus_recordcaretpos, NULL)); } /* ----------------------------------------------------------------------- */ /* Private functions */ static int _DCS_actions_handler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle) { ViewData *view_data; if(toolbox_get_client_handle(0, id_block->ancestor_id, (void **)&view_data) != NULL) return 0; /* Main window has probably been deleted already */ switch(event_code) { case DCS_Save: if(strchr(view_data->last_savepath, (int)'.') == NULL) { /* Must open savebox first */ RE(open_topleftofwin(Toolbox_ShowObject_AsMenu, savebox_sharedid, id_block->ancestor_id, id_block->self_id, id_block->self_component)) /* N.B. The savebox won't open immediately (until SaveAs_AboutToBeShown has been delivered). This gives us a chance to restore the caret to the main window and thus preserve the backwards link */ return 1; /* claim event */ } /* Save immediately */ { _kernel_oserror *err = perc_operation(FILEPERC_OP_COMP, view_data->last_savepath, FILETYPE_SKYCOLS, (flex_ptr)&view_data->sky); if(err != NULL) { /* Saving error */ err_report(err->errnum, msgs_lookup_sub1("SaveFail", err->errmess)); return 1; /* claim event */ } } /* After successful save, carry straight on as for Discard... */ case DCS_Discard: if(dcs_openparent) EditSky_openparentdir(view_data); /* Open parent directory */ /* the EditSky object's handlers will do the rest... */ RE(toolbox_delete_object(0, id_block->ancestor_id)) return 1; /* claim event */ } return 0; /* He's not the messiah, he's a very naughty boy! */ }